package com.efast.cafe.portal.controller.api;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.portal.service.api.IPortalApiFieldService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

/**
 * <p>
 * Controller
 * </p>
 * <p>
 * Table: portal_api_field - 字段定义
 * </p>
 *
 * @since 2017-08-10 02:36:09
 */
@Controller
@RequestMapping("/frame_center/api")
public class PortalApiFieldController extends AbstractController {

	@Autowired
	private IPortalApiFieldService portalApiFieldService;

	

	/**
	 * 根据项目id查询field
	 * 
	 * @param apiProjectBean
	 * @param request
	 * @return
	 */
	@RequestMapping("/field/query")
	public @ResponseBody ResultBean queryAll(HttpServletRequest request, @RequestBody JSONObject data) {
		ResultBean result = new ResultBean();

		if (StringUtils.isBlank(data.getString("objId"))) {
			result.setSuccess(false);
			result.setMessage("objId不能为空");
			return result;
		}
		try {
			Integer objectId = data.getInteger("objId");
			result.setSuccess(true);
			result.setObject(portalApiFieldService.queryByObjectId(objectId));
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			if (e instanceof ServiceException) {
				result.setMessage(e.getMessage());
			} else {
				// result.setMessage(context.getMessage(ADD_FAILURE_TIP));
			}
		}
		return result;
	}

}